﻿<%@ Page Title="货架基本资料" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
<link href="../assets/img/validate/validate.css" rel="stylesheet">
<style type="text/css">
.module-info .control-label{
	float: left;
	text-align: right;
	min-width: 110px;
}
@media (min-width: 528px) {
	.modal-dialog {
		width: 528px;
		margin: 10px auto;
	}
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container"></div>
            <div class="condition">        
                <label>搜索关键字</label>
                <input class="form-control input-w160" id="search-keys" placeholder="货架编号/名称" />
                <label>使用范围</label>
				<input type="text" class="form-control layer-date" readonly="readonly" id="search-start" placeholder="投入使用时间" />
				<label class="to">到</label>
				<input type="text" class="form-control layer-date" readonly="readonly" id="search-end" placeholder="停止使用时间" />
				<label>是否有效</label>
                <select id="isRemove" class="form-control input-w160">
					<option value="-1">全部</option>
					<option value="0">有效</option>
					<option value="1">无效</option>
				</select>
            </div>
            
            <div class="right-content-box">
            	<div class="ibox-content">
	                <table class="footable table table-stripped">
	                    <thead></thead>
	                    <tbody id="pageList"></tbody>
	                </table>
	            </div>
            </div>
            
            <div class="pageControl"></div>
        </div>
    </div>
	
	<div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
		<form id="checkModuleForm" method="get" action="#">
			<div class="modal-dialog">
				<div class="modal-content animated bounceInRight">
					<div class="modal-header">
						<span class="editTitle">货架基本信息</span>
						<button type="button" class="close" data-dismiss="modal">
							<span aria-hidden="true">&times;</span>
							<span class="sr-only">关闭</span>
                        </button>
					</div>
					<div id="message" style="display: none"></div>
					<div class="modal-body">
						<table class="module-info" cellpadding="0" cellspacing="0">
							<thead></thead>
							<tbody>
								<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">货架编号&nbsp;&nbsp;</label>
											<input id="Code" name="Code" placeholder="请输入货架编号" 
												datacol="yes" err="货架编号" checkexpession="NotNull"
												maxlength="20" class="form-control input-w360 required" />
										</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">货架名称&nbsp;&nbsp;</label>
											<input id="Name" name="Name" placeholder="请输入货架名称" 
												datacol="yes" err="货架名称" checkexpession="NotNull"
												maxlength="20" class="form-control input-w360 required" />
										</div>
									</td>
								</tr>
                                	<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">陈列类别&nbsp;&nbsp;</label>
											<input id="Category" name="Category" placeholder="请输入陈列类别" 
												datacol="yes" err="陈列类别" checkexpession="NotNull"
												maxlength="20" class="form-control input-w360 required" />
										</div>
									</td>
								</tr>
                                 	<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">代别&nbsp;&nbsp;</label>
											<input id="txtGeneration" name="txtGeneration" placeholder="请输入代别" 
												maxlength="10" class="form-control input-w360" />
										</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">投入使用时间&nbsp;&nbsp;</label>
											<input name="start" placeholder="投入使用时间" readonly="readonly" 
												datacol="yes" err="投入使用时间" checkexpession="NotNull"
												class="form-control layer-date input-w360 required" id="start">
                        				</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div class="form-group">
											<label class="control-label">停止使用时间&nbsp;&nbsp;</label>
                                            <input placeholder="停止使用时间" readonly="readonly" 
                                            	datacol="yes" err="停止使用时间" checkexpession="NotNull"
                                            	class="form-control layer-date input-w360 required" id="end" name="end">
										</div>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="modal-footer">
						<button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
						<button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</form>
	</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
<script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
<script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
<script src="../assets/js/framework.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/img/validate/learunui-validator.js"></script>
<script type="application/javascript">
$(document).ready(function () {
    //初始化日期控件
    var start = {
        elem: "#start",
        format: "YYYY-MM-DD",
        min: "2015-12-01",
        max: "2099-12-01",
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas;
            end.start = datas
        }
    };
    var end = {
        elem: "#end",
        format: "YYYY-MM-DD",
        min: laydate.now(),
        max: "2099-12-01",
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas
        }
    };
    var searchstart = {
        elem: "#search-start",
        format: "YYYY-MM-DD",
        min: "2015-12-01",
        max: "2099-12-01",
        istime: true,
        istoday: false,
        choose: function (datas) {
            searchend.min = datas;
            searchend.start = datas
        }
    };
    var searchend = {
        elem: "#search-end",
        format: "YYYY-MM-DD",
        min: "2015-12-01",
        max: "2099-12-01",
        istime: true,
        istoday: false,
        choose: function (datas) {
            searchstart.max = datas
        }
    };
    laydate(searchstart);
    laydate(searchend);
    laydate(start);
    laydate(end);
    //模块ID
    var ModuleID = Y.getUrlParam("ModuleID");
    
    //初始化图片展示
    $(".fancybox").fancybox({
    	openEffect:"none",
    	closeEffect:"none"
    });
    
    //用于记录页数
    var page = 1;
	//用于记录每页多少条记录
	var size = 500;

	var GSID = 0;
	var isCreate = true;
    commonUtil.loadBtnList(ModuleID,function(){
    	rScroll();
    	$('#editBtn').attr('disabled','disabled');
    	$('#deleteBtn').attr('disabled','disabled');
    });
    //加载信息列表
    var loadList = function(page){
    	if($('.footable thead').children().size() == 0)
			tableControl.initThead2('.footable',['图片','货架编号','货架名称','陈列类别','代别','投入时间','停止时间','是否有效']);
    	
    	pageControl.init('GoodShelf','List',{
			Keys: $('#search-keys').val(),
    		InjectDate: $('#search-start').val(),
    		StopDate: $('#search-end').val(),
    		IsRemove: $('#isRemove').val(),
    		Page: page,
//          		Size: size,
			alwaysCallBack:function(){
				GSID = 0;
				$('#editBtn').attr('disabled','disabled');
    			$('#deleteBtn').attr('disabled','disabled');
			}
		},function(result){
			page = result.page;
			var tBody = [];
			if (!Y.checkNull(result.data)) {
				if (result.data.Items.length > 0){
					result.data.Items.map(function(item,i){             		
						var tempTr = {
							trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
							children: [
								{tdText: item.GSID, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'hide'},
								{tdText: '', c:0 , r:0, tdHtml:'<a class="fancybox" href="'+ item.Image +'" title="'+ item.GSName +'"><img alt="image" src="'+ item.Image +'" class="itemPic" /></a>', tdId:'', tdClass:''},
								{tdText: (item.GSCode || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.GSName || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.Category || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.Generation || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: item.InjectDate.substring(0,10), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: item.StopDate.substring(0,10), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.IsRemove ? ' 无效 ' : ' 有效 '), c:0 , r:0, tdHtml: ('<i class="fa fa-'+ (!item.IsRemove ? 'check text-navy' : 'times text-danger') +'"></i>'), tdId:'', tdClass:''},
							]
						};
						tBody.push(tempTr);
					})
				}
				rScroll();
			}
			tableControl.initTbody('.footable',(tBody.length > 0 ? tBody : null),7,null);
		});
    }

    //新增按钮
	$('.btns-container').on('click', '#addBtn', function () {
	    isCreate = true;
	    $('.editTitle').text('新增-货架基本信息');
	    $('#Code').val(""),
        $('#Name').val(""),
        $('#start').val(""),
        $('#end').val(""),
        $('#Category').val(""),
	    $('#txtGeneration').val("")
	});
    //编辑按钮
	$('.btns-container').on('click', '#editBtn', function () {
	    isCreate = false;
	    $('.editTitle').text('编辑-货架基本信息');
	    loadDetail();
	    //layer.closeAll('dialog');
	});
	commonUtil.initDeleteBtnEvent({
	    callBack: function () {
	        Y.API2('GoodShelf', 'Remove', { ID: GSID }, function (data) {
	            layer.closeAll('dialog');
	            if (data.Success == false) {
	                swal('删除失败', data.Message, 'error');
	            } else {
	                swal('删除成功', '该信息已被你永久删除', 'success');
	                loadList(1);
	            }
	        });
	    }
	});
    //批量添加任务
	$(".btns-container").on("click",'#importBtn',function () {
	    $.ImportExcelTemplate({
	        filetype: 'Baseshelf', filename: '货架基本信息' , action: 'ImportTemplate', after: function () {
                //回调方法
	            loadList(1);
	        }
	    });
	});

	$('.btns-container').on('click', '#btn-search', function () {
	    loadList(1);
	});

	var loadDetail = function () {
	    layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
	    Y.API2('GoodShelf', 'Detail', { ID: GSID }, function (data) {
	        layer.closeAll('dialog');
	        if (data.Success == false) {
	            swal(data.Message, '', 'error');
	        } else {
	            $('#Code').val(data.GSCode);
	            $('#Name').val(data.GSName);
	            $('#start').val(data.InjectDate.substring(0, 10));
	            $('#end').val(data.StopDate.substring(0, 10));
	            $('#Category').val(data.Category);
	            $("#txtGeneration").val(data.Generation);
	        }
	    });
	}

    //选中记录
	$('#pageList').on('click', 'tr', function () {
	    //alert("aaaa"); return false;
	    var sid = $(this).find('td:first').text();
	    if (GSID == parseInt(sid))
	        return false;
	    GSID = parseInt(sid);
	    if (!isNaN(GSID))
	        $('#editBtn,#deleteBtn').removeAttr('disabled');
	    $('.footable tr').removeClass('check');
	    $(this).addClass('check');
	});

	loadList(1);
	//保存基本信息(新增或编辑)
	$('#addModuleBtn').click(function(){
		if (!CheckDataValid('#checkModuleForm')) {
            return false;
        }
		//检验通过后执行新增或者编辑
		var deal = '';
		var successText = '';
		if(isCreate){
			deal = 'Create';
			successText = '新增成功';
		}else{
			deal = 'Modify';
			successText = '编辑成功';
		}
		layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
		Y.API2('GoodShelf', deal, {
			ID: GSID,
			Code: $('#Code').val(),
			Name: $('#Name').val(),
			InjectDate:$('#start').val(),
			StopDate: $('#end').val(),
			Category: $('#Category').val(),
			Generation: $('#txtGeneration').val()
		},function(data){
			layer.closeAll('dialog');
			if(data.Success == false){
				swal(data.Message, '', 'error');
			}else{
				swal(successText, '', 'success');
				//关闭新建  or 编辑框
				$('#closeAddBox').click();
				//刷新列表
				loadList(1);
			}
		})
	})
})
</script>
</asp:Content>

